package cn.yunhe.servlet;

import cn.yunhe.services.OrderShowService;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 李非凡
 * 订单展示servlet
 */
@WebServlet("/shangjia/OrderShowServlet")
public class OrderShowServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/json;charset=UTF-8");
        PrintWriter out = response.getWriter();

        //缺少mid的取值
        int mid=(int)(request.getSession().getAttribute("mid"));
        OrderShowService orderShowService=new OrderShowService();
        JSONObject jsonObject=new JSONObject();
        JSONArray jsonArray=orderShowService.showOrder(mid);//mid从页面session取值
        int count=orderShowService.getOrderCount(mid);

        jsonObject.put("count",count);
        jsonObject.put("jsonArray",jsonArray);
        out.print(jsonObject);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
